from config import data_path
import os
import codecs


# stop words
stop_words = set()


def setup_stopwords():
    fr = codecs.open(data_path('stopwords.txt'), 'r', 'utf-8')
    for line in fr:
        stop_words.add(line.strip())


def filter_stop(words):
    return list(filter(lambda x: x not in stop_words, words))

# deny

deny_words = set()


def setup_deny_words():
    fr = codecs.open(data_path('denial.txt'), 'r', 'utf-8')
    for line in fr:
        deny_words.add(line.strip())


def count_deny(words):
    count = 0
    for word in words:
        if word in deny_words:
            count += 1
    return count

# extent

extent_words = dict()  # extent_words[word] = extent


def setup_extent_words():
    fr = codecs.open(data_path('extent.txt'), 'r', 'utf-8')
    for line in fr:
        line = line.split()
        extent_words[line[0]] = int(line[1])


def count_extent(words):
    extent = 0
    for word in words:
        if word in extent_words.keys():
            extent += extent_words[word]
    return extent

# polar

polar_words = dict()  # polar_words[word] = extent, >0 stands for pos, <0 stands for neg


def setup_polar():
    fr = codecs.open(data_path('polar.txt'), 'r', 'utf-8')
    for line in fr:
        line = line.split()
        polar_words[line[0]] = int(line[1])


def count_polar(words):
    extent = 0
    for word in words:
        if word in polar_words.keys():
            extent += polar_words[word]
    return extent

# setup


def setup():
    setup_stopwords()
    setup_deny_words()
    setup_extent_words()
    setup_polar()

setup()

if __name__ == '__main__':
    pass
